package leetcode_301_400;

import java.util.Arrays;

public class LeeCode_377 {
    public static void main(String[] args) {
        System.out.println(combinationSum4(new int[]{1, 2, 3}, 4));
    }
    private static int combinationSum4(int[] nums, int target) {
        Arrays.sort(nums);
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 1; i <= target; i++) {
            for (int num : nums) {
                if (i - num < 0)
                    break;
                dp[i] += dp[i - num];
            }
        }
        return dp[target];
    }
}
